********************************************************************************
******"Macroprudential Regulation, Quantitative Easing, and Bank Lending"*******
********************************************************************************
global y "lncdisbur_w199"
global ec3 "dT1e13 dT2e13 dT3e13 dT4e13 dT5e13 dT7e13 dT8e13 dT9e13 dT10e13 dT11e13 dT12e13"
global ed3top "dT1dtop85e13 dT2dtop85e13 dT3dtop85e13 dT4dtop85e13 dT5dtop85e13 dT7dtop85e13 dT8dtop85e13 dT9dtop85e13 dT10dtop85e13 dT11dtop85e13 dT12dtop85e13"
global controls "lncrefin dT*exlnassets dT*excashas"
global regcommands ", pool(5) compact absorb(bankid borrowerid#time) vce(cluster bankid)"

**# Bookmark (input)
clear *
import sas ENTE_SEGN CENSITO_CRITTOG TIME DISBUR COM COMUNE_DIP using $inputdirectory/bloans, case(lower)
run RO_creditregister tm(2014m6) tm(2015m6) 0
keep bankid borrowerid time disbur

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_gru2015, keepus(gru)
keep if _merge!=2
drop _merge
replace gru=bankid if gru==.
drop bankid
rename gru bankid
collapse (sum) disbur, by(bankid borrowerid time)

**# Bookmark (input)
merge m:1 bankid using $inputdirectory/INB_preann2014m12, keepus(e13 dtop85e13 exlnassets excashas ema4 ext1r extdaasepdec exnetinterbankas excbabserd0 excbabs4 exaqr)
keep if _merge==3
drop _merge

**# Bookmark (input)
merge m:1 bankid time using $inputdirectory/INB_refinm2015, keepus(lncrefin)
keep if _merge!=2
drop _merge

egen id=group(bankid borrowerid)
xtset id time
gen lncdisbur=100*(ln(disbur)-ln(L.disbur))
keep if time>=tm(2014m7)&time<=tm(2015m6)
winsor2 lncdisbur if lncdisbur!=., suffix(_w199) cuts(1 99)

run RO_tdummies 2015 12
run RO_tdintera 12 "e13 dtop85e13 exlnassets excashas ema4 ext1r extdaasepdec exnetinterbankas excbabserd0 excbabs4 exaqr"

**# Bookmark (output - IID)
est clear 
cd $outputdirectory
reghdfe $y $ec3 $controls dT*ema4 $regcommands
est save TABIID_C1234567
reghdfe $y $ec3 $controls dT*ext1r $regcommands
est save TABIID_C1234567, append
reghdfe $y $ec3 $controls dT*extdaasepdec $regcommands
est save TABIID_C1234567, append
reghdfe $y $ec3 $controls dT*exnetinterbankas $regcommands
est save TABIID_C1234567, append
reghdfe $y $ec3 $controls dT*excbabserd0 $regcommands
est save TABIID_C1234567, append
reghdfe $y $ec3 $controls dT*excbabs4 $regcommands
est save TABIID_C1234567, append
reghdfe $y $ec3 $controls dT*exaqr $regcommands
est save TABIID_C1234567, append

**# Bookmark (output - IIE)
reghdfe $y $ed3top $controls dT*ema4 $regcommands
est save TABIIE_C1234567
reghdfe $y $ed3top $controls dT*ext1r $regcommands
est save TABIIE_C1234567, append
reghdfe $y $ed3top $controls dT*extdaasepdec $regcommands
est save TABIIE_C1234567, append
reghdfe $y $ed3top $controls dT*exnetinterbankas $regcommands
est save TABIIE_C1234567, append
reghdfe $y $ed3top $controls dT*excbabserd0 $regcommands
est save TABIIE_C1234567, append
reghdfe $y $ed3top $controls dT*excbabs4 $regcommands
est save TABIIE_C1234567, append
reghdfe $y $ed3top $controls dT*exaqr $regcommands
est save TABIIE_C1234567, append

cd ..
